<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <title>Generate Utils</title>
    <link href="css/zui.min.css" rel="stylesheet" type="text/css" />

</head>

<body>
    <div class="container" style="margin-top: 100px;">

    </div>
    <div class="container">
        <div class="col-md-12">
            <div class="input-group col-md-6 container">
                <span class="input-group-addon ">UUID</span>
                <input id="input_uuid" type="text" class="form-control">
                <span class="input-group-btn">
                    <button id="copy_button1" class="btn btn-default" type="button"
                        data-clipboard-target="#input_uuid">复制</button>
                </span>
            </div>
        </div>

        <div class="col-md-12" style="margin-top: 35px;">
            <div class="input-group col-md-6 container">
                <span class="input-group-addon ">Timestamp</span>
                <input id="input_date_time" type="text" class="form-control">
                <span class="input-group-btn">
                    <button id="copy_button2" class="btn btn-default" type="button"
                        data-clipboard-target="#input_date_time">复制</button>
                </span>
            </div>
        </div>

    </div>

    <script src="js/jquery-1.11.3.min.js"></script>
    <script src="js/zui.min.js"></script>
    <script src="js/clipboard.min.js"></script>
    <script>
        $(function () {
            // -------------- UUID --------------
            // https://github.com/zenorocha/clipboard.js
            var clipboard = new ClipboardJS('#copy_button1');
            clipboard.on('success', function (e) {
                $('#input_uuid').val(generateUUID());

                e.clearSelection();

                new $.zui.Messager(' UUID 已复制到剪切板', {
                    time: 800,
                    type: 'success' // 定义颜色主题
                }).show();
            });
            $('#input_uuid').val(generateUUID());

            // -------------- Timestamp --------------
            $('#input_date_time').val(generateTimestamp());
            var clipboardDT = new ClipboardJS('#copy_button2');
            clipboardDT.on('success', function (e) {
                e.clearSelection();
                new $.zui.Messager(' Timestamp 已复制到剪切板', {
                    time: 800,
                    type: 'success' // 定义颜色主题
                }).show();
            });
            setInterval(function () {
                $('#input_date_time').val(generateTimestamp());
            }, 1000);
            

        });

        function generateUUID() {
            var d = new Date().getTime();
            if (window.performance && typeof window.performance.now === "function") {
                d += performance.now(); //use high-precision timer if available
            }
            var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = (d + Math.random() * 16) % 16 | 0;
                d = Math.floor(d / 16);
                return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
            });
            return uuid;
        }


        Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1,
                "d+": this.getDate(),
                "h+": this.getHours(),
                "m+": this.getMinutes(),
                "s+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3),
                "S": this.getMilliseconds()
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;

        };

        function generateTimestamp() {
            var dateTime = new Date();
            return dateTime.Format("yyyyMMddhhmmss");
        }
    </script>

</body>

</html>